package ui.videos 
{
	import com.gaiaframework.api.Gaia;
	import com.greensock.easing.Elastic;
	import com.greensock.TweenMax;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	import pages.Pages;
	import utils.ShapeUtil;
	import utils.SpriteUtil;
	import utils.TextFieldUtil;
	
	/**
	 * ...
	 * @author usual
	 */
	public class FriseItem extends MovieClip 
	{
		private var _container:MovieClip;
		private var _obj:Object;
		private var _toolTipItem:MaskMapMarker;
		private var _sh:Shape;
		private var _descriptionContainer:MovieClip;
		/*
		 * _obj.pageId
		 * _obj.tag
		 * _obj.title
		 * _obj.subtitle
		 * */
		public function FriseItem(obj:Object) 
		{
			_obj = obj;
			addContainer();
			addDescription();
		}
		
		private function addDescription():void 
		{
			_toolTipItem = new MaskMapMarker();
			_toolTipItem.scaleX = _toolTipItem.scaleY = 0.25;
			addChild(_toolTipItem);
			
			_descriptionContainer = new MovieClip();
			var desc:TextField = new TextField();
			desc.multiline = true;
			desc.wordWrap = true;
			desc.width = 300;
			desc.mouseEnabled = false;
			TextFieldUtil.setText(desc, "<descriptionVideo>" + _obj.description + "</descriptionVideo>");
			_descriptionContainer.addChild(desc);
			addChild(_descriptionContainer);
			//_toolTipItem.addChild(desc);
			//trace("[FriseItem.addDescription] ",_obj.description);
			
			_toolTipItem.x = _sh.x;
			_toolTipItem.y = _sh.y - (_toolTipItem.height / 2);
			_toolTipItem.alpha = _descriptionContainer.alpha = 0;
			
			_descriptionContainer.x = int(_toolTipItem.x - ((_descriptionContainer.width / 2)));
			_descriptionContainer.y = int(_toolTipItem.y - ((_descriptionContainer.height / 2)));
			
		}
		
		public function activate():void 
		{
			TweenMax.to(_container, 1, { tint:0x00ffff, delay:2 } );
			TweenMax.to(_sh, 1, { tint:0x00ffff, delay:2 } );

		}
		
		public function deactivate():void 
		{
			TweenMax.to(_container, 0.5, { removeTint:true,delay:1 } );
			TweenMax.to(_sh, 0.5, { removeTint:true,delay:1 } );
		}
		
		private function addContainer():void 
		{
			_container = new MovieClip();
			_container.alpha = 0;
			addChild(_container);
			var title:TextField = new TextField();
			title.multiline = true;
			title.wordWrap = true;
			title.width = 150;
			TextFieldUtil.setText(title, "<titleTimeLine>" + _obj.title + "</titleTimeLine>");
			_container.addChild(title);
			var subTitle:TextField = new TextField();
			subTitle.multiline = true;
			subTitle.wordWrap = true;
			subTitle.width = 150;
			TextFieldUtil.setText(subTitle, "<subTitleTimeLine>" + _obj.subtitle + "</subTitleTimeLine>");
			_container.addChild(subTitle);
			
			_sh = ShapeUtil.getCircle(5, 0xffffff);
			addChild(_sh);
			
			
			
			
			
			subTitle.y = title.y + title.height + 5;
			subTitle.x = (title.x + title.width) - (subTitle.width);
			
			
			_sh.x = title.x + (title.width/2);
			_sh.y = -8;
			subTitle.selectable = title.selectable = false;
			var bg:Sprite = SpriteUtil.drawRectSprite(_container.width, _container.height);
			bg.alpha = 0;
			bg.name = this.name;
			_container.addChild(bg)
			
			_container.buttonMode = true;
			_container.mouseChildren = false;
			_container.mouseEnabled = true;
			_container.addEventListener(MouseEvent.CLICK, clik);
			_container.addEventListener(MouseEvent.MOUSE_OVER, over);
			_container.addEventListener(MouseEvent.MOUSE_OUT, out);
			_container.cacheAsBitmap = true;
			//_container.rotation = -81;
			//_container.x = int(_sh.x-(_container.width/2))
			//_container.y =  int(_sh.x);
			//TweenMax.to(_container, 0, {transformAroundPoint:{point:new Point((_container.x+_container.width),0), rotation:-81}});
			TweenMax.to(_container, 1, { alpha:1 } );
			
		}
		
		private function out(e:MouseEvent=null):void 
		{
			trace("[FriseItem.out] ");
			TweenMax.to(_toolTipItem, .5, { alpha:0 } );
			TweenMax.to(_descriptionContainer, .5, { alpha:0 } );
		}
		
		private function over(e:MouseEvent):void 
		{
			trace("[FriseItem.over] ");
			TweenMax.to(_toolTipItem, .5, { alpha:1 } );
			TweenMax.to(_descriptionContainer, .5, { alpha:1 } );
		}
		
		private function clik(e:MouseEvent):void 
		{
			out();
			Gaia.api.goto(Pages.TIMELINE + '/' + this.name);
		}
		
	}

}